from app import db
from datetime import datetime

class MonitorPoint(db.Model):
    __tablename__ = 'monitor_points'
    
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    location = db.Column(db.String(128))
    description = db.Column(db.String(256))
    created_at = db.Column(db.DateTime, default=datetime.utcnow)

class MonitorData(db.Model):
    __tablename__ = 'monitor_data'
    
    id = db.Column(db.Integer, primary_key=True)
    point_id = db.Column(db.Integer, db.ForeignKey('monitor_points.id'), nullable=False)
    dissolved_oxygen = db.Column(db.Float)  # 溶解氧 mg/L
    ph_value = db.Column(db.Float)         # pH值
    temperature = db.Column(db.Float)       # 温度 ℃
    ammonia_nitrogen = db.Column(db.Float)  # 氨氮 mg/L
    turbidity = db.Column(db.Float)         # 浊度 NTU
    timestamp = db.Column(db.DateTime, default=datetime.utcnow)
    
    point = db.relationship('MonitorPoint', backref='data') 